package com.feilong.edgeAI.utils;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;

public class BackgroundLauncher {

    public BackgroundLauncher() {
    }

    public void launchAppInBackground(Context context,Intent launchIntent) {
        // 创建一个意图，指定要启动的Activity
//        Intent launchIntent = new Intent(context, MainActivity.class);
//        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        // 创建一个PendingIntent，用于在后台启动APP
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        // 获取AlarmManager实例
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        // 设置一个延迟，指定多久后启动APP，这里设置为10秒后
        long delay = SystemClock.elapsedRealtime() + 10;

        // 使用AlarmManager在指定的延迟后启动APP
        alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, delay, pendingIntent);
    }
}